console.log('(Server) Hello World!');
import './admin';
import './prizeDraw';
// let state = false;
// world.onPress(({ button }) => {
//     if (button === GameButtonType.ACTION0 && !state) {
//         state = true;
//         main();
//     }
// });

/**
 * 获取地图ID
 */
import { getMapId } from './getMapId/App';
console.log(getMapId());

import { hangingFunc, hanging } from './hanging';
hangingFunc();
/**
 * 对接client端作品展厅
 */
import { hall } from './hall';
hall();

function sendClient(
    entity: GamePlayerEntity | GamePlayerEntity[],
    type: string,
    data: object | string | number
) {
    remoteChannel.sendClientEvent(entity, {
        type,
        data,
    });
}

setInterval(() => {
    sendClient(
        world.querySelectorAll('player'),
        'online',
        world.querySelectorAll('player').map((e) => {
            return {
                name: e.player.name + (hanging(e) ? '[挂机]' : ''),
                userId: e.player.userId,
                avatar: e.player.avatar,
                hanging: hanging(e),
            };
        })
    );
}, 100);

import type { RemoteAwardData } from '../../shares/sharesApp';
const awards = [
    '优秀视频奖1',
    '优秀视频奖2',
    '最佳视频奖1',
    '最佳视频奖2',

    '优秀模型奖1',
    '优秀模型奖2',
    '优秀模型奖3',
    '优秀模型奖4',
    '优秀模型奖5',
    '优秀模型奖6',
    '优秀模型奖7',
    '优秀模型奖8',
    '优秀模型奖9',

    '最佳模型奖1',
    '最佳模型奖2',
    '最佳模型奖3',

    '优秀建筑奖1',
    '优秀建筑奖2',
    '优秀建筑奖3',
    '优秀建筑奖4',

    '最佳建筑奖1',
    '最佳建筑奖2',
    '最佳建筑奖3',
    '最佳建筑奖4',

    '最佳地图二创奖1',
];
world.onChat(({ entity, message }) => {
    if (
        entity.player?.userId !== '50041641' &&
        entity.player?.userId !== '13048627'
    ) {
        return;
    }
    if (awards.includes(message)) {
        console.log(1);
        const users = world.querySelectorAll('player') as GamePlayerEntity[];
        remoteChannel.sendClientEvent(users, {
            type: 'award',
            data: `picture/${message}.jpg`,
        });
    } else if (message === '隐藏奖状') {
        remoteChannel.sendClientEvent(world.querySelectorAll('player')!, {
            type: 'award',
            data: -1,
        });
    }
});
